package FileMethodTest;

import org.junit.Test;

import java.io.File;
import java.io.IOException;

/**
 * @author 李泽伟
 */
public class MainTest {
    public static void main(String[] args) {
        File file = new File("hello.txt");
        if (!file.exists()) {
            try {
                boolean b = file.createNewFile();
                if (b) {
                    System.out.println("文件创建成功");
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }else {
            System.out.println("删除文件");
            boolean b = file.delete();
        }

        File io = new File("IO");
        boolean mkdir = io.mkdir();
        if(mkdir){
            System.out.println("文件夹IO创建成功");
        }
        File file1 = new File("IO/IOTest");
        boolean b = file1.mkdirs();
        if (b) {
            System.out.println("多级目录IO/IOTest创建成功");
        }
    }

    @Test
    public void test4(){
        File file = new File("D:\\Lizejiang\\importantNetworkCourse\\JavaLearn\\JavaCode\\JavaSELearn");
        dfs(file);
    }
    public void dfs(File file){
        File[] files = file.listFiles();
        assert files != null;
        for(File f : files){
            if(f.isFile()){
                System.out.println(f.getName());
            }else {
                dfs(f);
            }
        }
    }
}
